﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HNQXYJ.Model;
using HNQXYJ.BLL;

namespace HNQXYJ.HN_User
{
    public partial class UsersUpdatePwd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void reset_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("UserMgr.aspx", true);
        }

        protected void add_Click(object sender, ImageClickEventArgs e)
        {
            int id = Convert.ToInt32(Request["id"]);
            Users user = new Users();
            UsersBLL ub = new UsersBLL();
            user = ub.GetUserDataById(id);
            if (user != null)
            {
                string oldPwd =UsersBLL.GetMD5(this.txtOldPwd.Text.Trim());
                if (oldPwd.Equals(user.Password))//输入的旧密码正确
                {
                    user.Password = UsersBLL.GetMD5(this.txtNewPwd.Text.Trim());
                    if ( !this.txtNewPwd.Text.Trim().Equals(this.txtConfirmPwd.Text.Trim()))
                    {
                        this.Label1.Text = "新密码两次输入不一致";
                        return;
                    }
                    bool flage = ub.UpateUserPassword(user);
                    if (flage)
                    {
                        Response.Redirect("UserMgr.aspx", true);
                    }
                    else
                    {
                        this.Label1.Text = "密码更新失败";
                        return;
                    }
                }
                else
                {
                    this.Label1.Text = "你输入的旧密码不正确！";
                    return;
                }
            }

        }
    }
}